package leetcode;

public class LeetCode82 {

    public ListNode deleteDuplicates(ListNode head) {
        ListNode result = new ListNode(-1), q = result;
        ListNode p = head;
        while (p != null) {
            if (p.next == null || p.val != p.next.val) {
                q.next = p;
                q = q.next;
                p = p.next;
            } else {
                int val = p.val;
                while (p != null && p.val == val) {
                    p = p.next;
                }
            }
        }
        q.next = null;
        return result.next;
    }
}
